import pytest
import functools
import time

def log_execute_time(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        start = time.perf_counter()
        res = func(*args, **kwargs)
        end = time.perf_counter()
        print("{} 用时 {} ms".format(func.__name__, (end - start) * 1000))
        return res
    return wrapper

@log_execute_time
def test_01():
    a = 1
    b = 2
    assert a < b

@log_execute_time
def test_02():
    a = 1
    b = 1
    assert a-b == 0


#如果我想在运行结果里看到每个case的执行时长，那么就可以写一个装饰器去处理：
if __name__ == '__main__':
    pytest.main(['-s','test1.py'])